#!/usr/bin/php -q
<?php
/**
 *
 */

require_once( 'demon.php' );

var_dump( $argv );

//test_boot_one();
//test_kill_one();

test_demonize();

?>
<?php

function	test_boot_one( )
{
	$action = 'boot';
	$name = 'hello';
	$dir_proc = '/tmp/proc';
	
	$demon = new Demon( $action, $name, $dir_proc );
	$demon->start();
	
	$files = glob( "{$dir_proc}/*" );
	foreach( $files as $file ) {
		echo "PID : ",$file,"\n";	
		$content = file_get_contents( $file );
		echo ">>> ",$content,"\n";
	}
	
	$demon->stop();
}

function	test_kill_one ( )
{
	$action = 'kill';
	$name = 'hello';
	$dir_proc = '/tmp/proc';
	
	$demon = new Demon( $action, $name, $dir_proc );
	$demon->kill();
	
	$files = glob( "{$dir_proc}/*" );
	foreach( $files as $file ) {
		echo "PID : ",$file,"\n";	
		$content = file_get_contents( $file );
		echo ">>> ",$content,"\n";
	}
	
	$demon->stop();
}

function	test_demonize()
{
	global	$argv;
	
	$demon = demonize( $argv );
	if ( !$demon ) {
		echo "fail to demonize.\n";
		return	false;
	}

	if ( $demon ) { 
		$demon->start();	
	}
	
	$dir_proc = '/tmp/proc';
	$files = glob( "{$dir_proc}/*" );
	foreach( $files as $file ) {
		echo "PID : ",$file,"\n";	
		$content = file_get_contents( $file );
		echo ">>> ",$content,"\n";
	}
	
	sleep( 30 );

	if ( $demon ) {
		$demon->stop();
	}
}

?>
